/*
 * Token.hpp
 *
 *  Created on: 04.10.2012
 *      Author: dom
 */

#ifndef TOKEN_HPP_
#define TOKEN_HPP_

#include <string>
#include <memory>

#include "document.hpp"

namespace mpei {

template<typename _T = std::string, typename _E = double>
class Token {
	typedef Document<Token<_T, _E>> document;
public:
	typedef _T key_type;
	typedef _E value_type;
	typedef std::shared_ptr<Token<_T, _E>> shared_ptr;

	Token();

	Token(const _T & token) :
			doc(nullptr), name(token), frequency(0), tf_weight(0), tf_idf_weight(
					0) {
	}

	virtual ~Token() {

	}

	friend shared_ptr & operator ++(shared_ptr & token) {
		++(token->frequency);
//		if(token->doc == nullptr)
//			throw std::runtime_error(token->name + " is not documents token");
		return token;
	}

	Token & operator ++(int) {
		++frequency;
		return *this;
	}

	friend bool operator==(const shared_ptr & __lhs, const shared_ptr & __rhs) {
		return __lhs->name == __rhs->name;
	}

	friend inline bool operator<(const shared_ptr& __lhs, const shared_ptr& __rhs) {
		return __lhs->frequency < __rhs.frequency;
	}

	friend inline bool operator>(const shared_ptr& __lhs, const shared_ptr& __rhs) {
		return __lhs.frequency > __rhs.frequency;
	}

	_T data() {
		return this->name;
	}

	void setFrequency(_E freq) {
		frequency = freq;
	}
	_E getFrequency() {
		return frequency;
	}

	_E getTf() {
		return tf_weight;
	}

	void setTf(_E & tf_weight) {
		this->tf_weight = tf_weight;
	}

	void setTfIdf(_E & tf_idf_weight) {
		this->tf_idf_weight = tf_idf_weight;
	}

	_E getTfIdf() {
		return tf_idf_weight;
	}

	void setDocument(document * doc) {
		this->doc = doc;
	}

	void setTfc(_E & tfc_weight) {
			this->tfc_weight = tfc_weight;
		}

	_E getTfc() {
		return tfc_weight;
	}

	void setLtc(_E & ltc_weight) {
			this->ltc_weight = ltc_weight;
		}

	_E getLtc() {
		return ltc_weight;
	}

	void setAtc(_E & atc_weight) {
			this->atc_weight = atc_weight;
		}

	_E getAtc() {
		return atc_weight;
	}

	document * getDocument() {
		return doc;
	}

protected:
	document * doc;
	_T name;
	_E frequency;
	_E tf_weight;
	_E tf_idf_weight;
	_E tfc_weight;
	_E ltc_weight;
	_E atc_weight;
};

typedef Token<std::string, double> token_t;

}  // namespace mpei

#endif /* TOKEN_HPP_ */
